package core.hmxchen.test.one;
import core.hmxchen.log.annotation.LogPrint;
import core.hmxchen.log.enums.Level;
import core.hmxchen.log.enums.Print;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 *@ClassName LogPintController
 *@Description TODO
 *@Author hmxchen
 *@version v1.0.0
 *@Date 2021/9/5 16:12 
 */
@RestController
@RequestMapping("/log/print")
public class LogPintController {
    @LogPrint(biz = "普通测试-输出所有")
    @GetMapping("/logTest1")
    public Map<String, Object> logTest1(HttpServletRequest request, Map<String, Object> param) {
        Map<String, Object> result = new HashMap<>(3);
        result.put("code", 200);
        result.put("msg", "success");
        result.put("data", param);
        return result;
    }
    @LogPrint(biz = "测试输入参数",level = Level.INFO,print = Print.DO_BEFORE_LOG)
    @GetMapping("/logTest2")
    public Map<String, Object> logTest2(HttpServletRequest request, Map<String, Object> param) {
        Map<String, Object> result = new HashMap<>(3);
        result.put("code", 200);
        result.put("msg", "success");
        result.put("data", param);
        return result;
    }
    @LogPrint(biz = "测试输出结果",level = Level.INFO,print = Print.AFTER_RETURN_LOG)
    @GetMapping("/logTest21")
    public Map<String, Object> logTest21(HttpServletRequest request, Map<String, Object> param) {
        Map<String, Object> result = new HashMap<>(3);
        result.put("code", 200);
        result.put("msg", "success");
        result.put("data", param);
        return result;
    }
    @LogPrint(biz = "测试输出异常",level = Level.INFO,print = Print.AFTER_THROW_LOG)
    @GetMapping("/logTest22")
    public Map<String, Object> logTest22(HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>(3);
        result.put("code", 200);
        result.put("msg", "success");
        result.put("data", 1/0);
        return result;
    }
    @LogPrint(biz = "测试拦截输入参数",level = Level.INFO,print = Print.DO_BEFORE_LOG,paramFilter = {"request"} )
    @GetMapping("/logTest3")
    public Map<String, Object> logTest3(HttpServletRequest request, Map<String, Object> param) {
        Map<String, Object> result = new HashMap<>(3);
        result.put("code", 200);
        result.put("msg", "success");
        result.put("data", param);
        return result;
    }
    @LogPrint(biz = "测试指定格式化实现类",level = Level.INFO,print = Print.AROUND_LOG ,logImplClass = "core.hmxchen.test.logimpl.RequestLogImpl")
    @GetMapping("/logTest31")
    public Map<String, Object> logTest31(HttpServletRequest request, Map<String, Object> param) {
        Map<String, Object> result = new HashMap<>(3);
        result.put("code", 200);
        result.put("msg", "success");
        result.put("data", param);
        return result;
    }
}
